<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>添加萤火虫插件</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
<link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
<style>
    .layui-card-header{width:80px;text-align: right;float:left;}
    .layui-card-body{margin-left:28px;}
    .layui-upload-img{width: 92px; height: 92px; margin: 0 10px 10px 0;}

    .up{position: relative;display: inline-block;cursor: pointer;border-color: #1ab394; color: #FFF;width: 92px !important;font-size: 10px !important;text-align: center !important;}
    .up input{position: absolute;top:0;left: 0;display: block;opacity: .01;width: 100px;height:30px;}
    .layui-upload-list{width: 100px;height:96px;overflow: hidden;}
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {-webkit-appearance: none !important;margin: 0;}
</style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card" style="margin-top:0px">
        <div class="layui-card-header" style="width:auto !important">添加萤火虫插件&nbsp;&nbsp;&nbsp;<span class="zong_school_name"></span></div>
        <div class="layui-card-body" style="padding: 15px;">
            <div class="layui-form" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">门店名称</label>
                    <div class="layui-input-block">
                        <div class="store_name" style="line-height: 36px;"></div>
                    </div>
                </div>
                <div class="layui-form-item school">
                    <label class="layui-form-label">收银员</label>
                    <div class="layui-input-block">
                        <select name="store" id="store" lay-filter="store">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item school">
                    <label class="layui-form-label">收银机品牌</label>
                    <div class="layui-input-block">
                        <select name="till" id="till" lay-filter="till">
                        </select>
                    </div>
                </div>
                
                <div class="layui-form-item school school1" style="display:none">
                    <label class="layui-form-label">萤火虫插件软件</label>
                    <div class="layui-input-block">
                        <select name="till1" id="till1" lay-filter="till1">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item school school2" style="display:none">
                    <label class="layui-form-label">萤火虫软件版本</label>
                    <div class="layui-input-block">
                        <select name="till2" id="till2" lay-filter="till2">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">聪明付商户号</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="title" autocomplete="off" placeholder="请输入聪明付商户号" class="layui-input device_key" class="shop_id">
                    </div>
                    <div style="color:red;margin:5px">系统提示:该商户在聪明付存在,在本平台不存在的填写</div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn submit site-demo-active" data-type="tabChange">确定提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="storeid">
<input type="hidden" class="brand_id">
<input type="hidden" class="produce_uid">
<input type="hidden" class="storename">
<input type="hidden" class="soft_version_uid">
<input type="hidden" class="soft_uid">

<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script> 
<script src="{{asset('/layuiadmin/jquery.min.js')}}"></script>
<script src="{{asset('/layuiadmin/jquerysession.js')}}"></script>
<script>
    var token = localStorage.getItem("Usertoken");
    // var str=location.search;
    // var school_name=str.split('?')[1];
    var store_id="{{$_GET['store_id']}}";
    var store_name="{{$_GET['store_name']}}";

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        formSelects: 'formSelects'
    }).use(['index', 'form','upload','formSelects','element'], function(){
        var $ = layui.$ 
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,upload = layui.upload
            ,formSelects = layui.formSelects;

        var src=$('#demo1').attr('src');
        element.render();
        $('.store_name').html(store_name);
        
        // 选择业务员
        $.ajax({
            url : "{{url('/api/basequery/merchant_lists')}}",
            data : {token:token,store_id:store_id},
            type : 'post',
            success : function(data) {
                var optionStr = "";
                for(var i=0;i<data.data.length;i++){
                    optionStr += "<option value='" + data.data[i].merchant_id + "'>" + data.data[i].name + "</option>";
                }
                $("#store").html('');
                $("#store").append('<option value="">选择收银员</option>'+optionStr);
                layui.form.render('select');
            },
            error : function(data) {
                alert('查找板块报错');
            }
        });
        
        // 收银机品牌
        $.ajax({
            url :  "{{url('api/devicepay/yhc_initdevicebrand')}}",
            data : '',
            type : 'post',
            success : function(data) {
                var data=JSON.parse(data);
                var optionStr = "";
                var optionStr1 = "";
                for(var i=0;i<data.list.length;i++){
                    optionStr += "<option value='" + data.list[i].brand_id + "'>" + data.list[i].brand_name + "</option>";
                }
                $("#till").html('');
                $("#till").append('<option value="">选择收银机品牌</option>'+optionStr);
                layui.form.render('select');
            },
            error : function(data) {
                alert('查找板块报错');
            }
        });
        
        form.on('select(till)', function(data){
            brand_id = data.value;
            $('.brand_id').val(brand_id);
            if(data.value=='gww'||data.value=='yhc_v5'){
                $.ajax({
                    url : "{{url('api/devicepay/yhc_initdevicebrand')}}",
                    data : '',
                    type : 'post',
                    success : function(data1) {
                        var data1=JSON.parse(data1);
                        var optionStr1 = "";
                        for(var i=0;i<data1.list.length;i++){
                            if(data1.list[i].brand_id==brand_id){
                                var gww_list=JSON.parse(data1.list[i].gww_list);
                                console.log(gww_list);
                                for(var t=0;t<gww_list.length;t++){
                                    if(brand_id=='yhc_v5'){
                                        optionStr1 += "<option value='" + gww_list[t].uuid + "'>" + gww_list[t].name + "</option>";
                                    }else{
                                        optionStr1 += "<option value='" + gww_list[t].uid + "'>" + gww_list[t].name + "</option>";
                                    }
                                    $("#till1").html('');
                                    $("#till1").append('<option value="">选择插件软件</option>'+optionStr1);
                                    layui.form.render('select');
                                }
                            }
                        }
                    }
                });
                $('.school1').css('display','block');
            }else{
                $('.school1').css('display','none');
                $('.school2').css('display','none');
            }
        });
        
        form.on('select(till1)', function(data){
            produce_uid = data.value;
            $('.produce_uid').val(produce_uid);
            var brand_id=$('.brand_id').val();
            
            if(brand_id=='yhc_v5'){
                // 选择设备类型
                $.ajax({
                    // url : "https://pay.zgjindoufu.com/api/devicepay/yhc_inityhcv5softmsg",
                    url : "{{url('/api/devicepay/yhc_inityhcv5softmsg')}}",
                    data : {produce_uid:$('.produce_uid').val()},
                    type : 'post',
                    success : function(data) {
                        var data=JSON.parse(data);
                        console.log(data)
                        var optionStr = "";
                        for(var i=0;i<data.data.length;i++){
                            optionStr += "<option value='" + data.data[i].uuid + "'>"
                                + data.data[i].name + "</option>";
                        }
                        $("#till2").html('');
                        $("#till2").append('<option value="">选择插件版本</option>'+optionStr);
                        layui.form.render('select');
                    },
                    error : function(data) {
                        alert('查找板块报错');
                    }
                });  
            }else{
            // 选择设备类型
            $.ajax({
                // url : "https://pay.zgjindoufu.com/api/devicepay/yhc_initgwwsoftmsg",
                url : "{{url('/api/devicepay/yhc_initgwwsoftmsg')}}",
                data : {produce_uid:$('.produce_uid').val()},
                type : 'post',
                success : function(data) {
                    var data=JSON.parse(data);
                    console.log()
                    var optionStr = "";
                    for(var i=0;i<data.soft.data.length;i++){
                        optionStr += "<option value='" + data.soft.data[i].uid + "'>"
                            + data.soft.data[i].soft_name + "</option>";
                    }
                    soft_version_uid=data.coreversion.data[0].uid
                    $('.soft_version_uid').val(soft_version_uid);
                    $("#till2").html('');
                    $("#till2").append('<option value="">选择插件版本</option>'+optionStr);
                    layui.form.render('select');
                },
                error : function(data) {
                    alert('查找板块报错');
                }
            });  
            }
            $('.school2').css('display','block');
        });
        
        form.on('select(till2)', function(data){
            soft_uid = data.value;
            $('.soft_uid').val(soft_uid);
        });
        
        form.on('select(store)', function(data){            
            category = data.value; 
            categoryName = data.elem[data.elem.selectedIndex].text; 
            $('.storeid').val(category);
            $('.storename').val(categoryName);           
        });
        
        $('.submit').on('click', function(){
            var pass =$.session.get('pass');
            // 重置cookie有效期
            var time = Date.parse(new Date()) + (5 * 60 * 1000);
            $.session.set('time', time);
            
            $.post("{{url('/api/glow/add_code')}}",
            {
                token:token,
                store_id:store_id,
                merchant_id:$('.storeid').val(),
                shop_id:$('.shop_id').val(),
                soft_uid:$('.soft_uid').val(),
                brand_id:$('.brand_id').val(),
                soft_version_uid:$('.soft_version_uid').val(),
                pass: pass,
                path: 'api/glow/add_code',
            },function(res){
//                console.log(res);
                if(res.status==1){
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 1
                        ,time: 3000
                    });                    
                }else{
                    layer.msg(res.message, {
                        offset: '50px'
                        ,icon: 2
                        ,time: 3000
                    });
                }
            },"json");
        });

    });

</script>

</body>
</html>
